﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Vit.Web.Providers.Data;

namespace Vit.DynamicFormModule.Areas.Form.DataProviders
{
    public class DynamicFormDataProvider : DbContextDataProvider<DynamicFormDb, Models.DynamicForm>
    {
        protected override IQueryable<Models.DynamicForm> OrderByDefault(IQueryable<Models.DynamicForm> query)
        {
            return query.OrderBy(o => o.FormName);
        }

        public override object[] GetKeys(Models.DynamicForm obj)
        {
            return new object[] { obj.FormName };
        }

        public override Models.DynamicForm GetByKeys(params object[] ids)
        {
            if (ids == null || ids.Length != 1)
                return null;
            string key = ids[0].ToString();
            return db.Forms.FirstOrDefault(o => o.FormName == key);
        }
    }
}